Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Jambo build validation hook #229

Merged
merged 8 commits into from
Jun 8, 2021
Merged

Add Jambo build validation hook #229

merged 8 commits into from
Jun 8, 2021

Conversation

yen-tt
Copy link
Contributor

@yen-tt yen-tt commented Jun 7, 2021

  • Added another operation inside PageWriter to ensure template data is correct
    using TemplateDataValidator, which pass in the formatted config data to the theme's validation
    hook function

J=SLAP-1369
TEST=auto

Created Jest tests using default config format with/without missing field when
pass to validation hook and check if errors are handle properly

- Added another operation inside PageWriter to ensure template data is correct
using TemplateDataValidator, which pass in the templateArgument to the theme's validation
hook function if it exists

J=SLAP-1369
TEST=auto

Passed Jest test using default config format with/without missing field when
pass to validation hook
@yen-tt yen-tt force-pushed the dev/validation-hook branch from b8d8dc5 to 2fc6aa0 Compare June 7, 2021 14:09
@coveralls
Copy link

coveralls commented Jun 7, 2021

Coverage Status

Coverage increased (+0.4%) to 46.72% when pulling ac06045 on dev/validation-hook into d9ecec9 on develop.

try {
info(`Validating configuration for page "${pageName}".`);
const validatorFunction = require(this._templateDataValidationHook);
validatorFunction(pageData);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we want this class and the hook to throw an exception when the data is invalid. The alternative is that both return a boolean. I think the boolean has its advantages:

  • Consumers of the validators can more easily decide how they want to handle bad templates. It may be that they thrown an exception if the validation result is false. Or, they try and handle more gracefully. As an example, in the future, maybe users can configure Jambo to gracefully ignore bad pages and continue generation (although I think the more catastrophic failure is the way to go for now).
  • We can differentiate between an actual issue running the Theme supplied validator and an invalid template. Right now, if there was an exception thrown because the validator couldn't run properly, we would treat that the same as the validator finding the template to be no good. We should probably treat the two situations differently and give different errors.

Copy link
Contributor Author

@yen-tt yen-tt Jun 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, it would give user more flexibility on exception handling. This would fall on the Theme’s hook to log in detail what is invalid, and the pageWriter will throw a new error of general bad template if hook return false. Updated in new commit

@yen-tt yen-tt requested review from tmeyer2115 and cea2aj June 8, 2021 15:30
}

/**
* Writes a file to the output directory per page in the given PageSet.
*
* @param {PageSet} pageSet the collection of pages to generate
* @throws {UserError} on missing config(s)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nit: It's not so much that the error is thrown for missing config(s) but for template data that fails a Theme's validation. In theory, it could fail for any number of reasons: missing keys, improperly structured data, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added that to address existing code (line 59) where it checks for config file, but forgot to include the new errors throw from the validation. Going to update that

@yen-tt yen-tt merged commit 5a4afc7 into develop Jun 8, 2021
@yen-tt yen-tt deleted the dev/validation-hook branch June 8, 2021 20:39
@oshi97 oshi97 mentioned this pull request Aug 24, 2021
oshi97 added a commit that referenced this pull request Aug 24, 2021
* Do not run the babel helper in Development Mode. (#224) (#225)
* Use npmlog for logging with colors (#228)
* Add Jambo build validation hook (#229)
* Added acceptance testing framework + tests 
* add --globs param to `jambo extract-translations` (#233) 
* Pass partials to templatedatavalidator (#237)
* `jambo upgrade` no longer deletes the themes folder if there is an error when git checkout-ing the new branch (#235)
* Update canonicalizeLocale to handle 中文(chinese) (#239)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants